Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make parts of the BlockNavigationList overridable using slots #21948

Conversation

adamziel
Copy link
Contributor

@adamziel adamziel commented Apr 28, 2020

Description

First attempt at #20748

This PR makes it possible to plug into BlockNavigationList using slots.

How has this been tested?

  1. Apply this PR and Allow editing of new menu items from the block inspector #22210

On experimental nav-menus page:

  1. Go to /wp-admin/admin.php?page=gutenberg-navigation

  2. Edit the text from the navigation structure panel like on the gif below:

  3. Try with both top-level and nested navigation items

In posts editor:

  1. Go to posts > add new
  2. Add navigation block with some nested items
  3. Try editing titles through the navigator in block inspector (slow! performance fix: Optimize BlockStyles by using hooks and React.memo (instead of HOCs) #21973):

Zrzut ekranu 2020-04-29 o 13 35 11

  1. Make sure to use rich formatting like pressing enter or using keyboard shortcuts (e.g. cmd+b on mac to bold selected text).

  2. Try editing titles through the navigator in modal:

Zrzut ekranu 2020-04-29 o 13 35 17

  1. Confirm global block navigation remains non-editable and only allows block selection on click:

Zrzut ekranu 2020-04-29 o 13 36 15

Screenshots

2020-04-28 16-01-11 2020-04-28 16_01_34

Types of changes

Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@github-actions
Copy link

github-actions bot commented Apr 28, 2020

Size Change: +2.45 kB (0%)

Total Size: 824 kB

Filename Size Change
build/api-fetch/index.js 4.08 kB +1 B
build/block-directory/index.js 6.61 kB +5 B (0%)
build/block-editor/index.js 102 kB +994 B (0%)
build/block-editor/style-rtl.css 10.3 kB +130 B (1%)
build/block-editor/style.css 10.3 kB +129 B (1%)
build/block-library/editor-rtl.css 7.12 kB +42 B (0%)
build/block-library/editor.css 7.12 kB +40 B (0%)
build/block-library/index.js 115 kB +6 B (0%)
build/block-library/style-rtl.css 7.34 kB +59 B (0%)
build/block-library/style.css 7.34 kB +55 B (0%)
build/blocks/index.js 48.1 kB +6 B (0%)
build/components/index.js 180 kB +536 B (0%)
build/components/style-rtl.css 17 kB +42 B (0%)
build/components/style.css 16.9 kB +41 B (0%)
build/compose/index.js 6.66 kB -2 B (0%)
build/core-data/index.js 11.4 kB +14 B (0%)
build/data/index.js 8.45 kB +4 B (0%)
build/edit-navigation/index.js 4.41 kB +339 B (7%) 🔍
build/edit-navigation/style-rtl.css 618 B +133 B (21%) 🚨
build/edit-navigation/style.css 617 B +132 B (21%) 🚨
build/edit-post/index.js 28 kB -140 B (0%)
build/edit-post/style-rtl.css 12.2 kB +20 B (0%)
build/edit-post/style.css 12.2 kB +20 B (0%)
build/edit-site/index.js 12.1 kB -180 B (1%)
build/edit-site/style-rtl.css 5.22 kB +25 B (0%)
build/edit-site/style.css 5.22 kB +24 B (0%)
build/edit-widgets/index.js 8.37 kB -4 B (0%)
build/edit-widgets/style-rtl.css 4.69 kB +13 B (0%)
build/edit-widgets/style.css 4.69 kB +12 B (0%)
build/editor/editor-styles-rtl.css 425 B -3 B (0%)
build/editor/editor-styles.css 428 B -3 B (0%)
build/editor/index.js 44.3 kB -36 B (0%)
build/element/index.js 4.65 kB +1 B
build/format-library/index.js 7.63 kB -1 B
build/hooks/index.js 2.14 kB +7 B (0%)
build/keyboard-shortcuts/index.js 2.51 kB -1 B
build/keycodes/index.js 1.94 kB -1 B
build/list-reusable-blocks/index.js 3.12 kB -2 B (0%)
build/media-utils/index.js 5.29 kB +1 B
build/notices/index.js 1.79 kB -1 B
build/nux/index.js 3.4 kB +1 B
build/plugins/index.js 2.56 kB +1 B
build/primitives/index.js 1.5 kB -2 B (0%)
build/redux-routine/index.js 2.85 kB -2 B (0%)
build/rich-text/index.js 14.8 kB -3 B (0%)
build/server-side-render/index.js 2.68 kB +2 B (0%)
build/token-list/index.js 1.28 kB -1 B
build/url/index.js 4.02 kB +1 B
build/viewport/index.js 1.84 kB -1 B
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.02 kB 0 B
build/annotations/index.js 3.62 kB 0 B
build/autop/index.js 2.82 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/style-rtl.css 760 B 0 B
build/block-directory/style.css 761 B 0 B
build/block-library/theme-rtl.css 683 B 0 B
build/block-library/theme.css 685 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/data-controls/index.js 1.29 kB 0 B
build/date/index.js 5.47 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 3.1 kB 0 B
build/editor/style-rtl.css 5.07 kB 0 B
build/editor/style.css 5.08 kB 0 B
build/escape-html/index.js 734 B 0 B
build/format-library/style-rtl.css 502 B 0 B
build/format-library/style.css 502 B 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/is-shallow-equal/index.js 710 B 0 B
build/list-reusable-blocks/style-rtl.css 226 B 0 B
build/list-reusable-blocks/style.css 226 B 0 B
build/nux/style-rtl.css 616 B 0 B
build/nux/style.css 613 B 0 B
build/priority-queue/index.js 789 B 0 B
build/shortcode/index.js 1.7 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.18 kB 0 B

compressed-size-action

@adamziel adamziel added [Block] Navigation Affects the Navigation Block [Feature] List View Menu item in the top toolbar to select blocks from a list of links. and removed [Status] In Progress Tracking issues with work in progress labels Apr 28, 2020
@adamziel adamziel marked this pull request as ready for review April 28, 2020 14:02
@adamziel adamziel marked this pull request as draft April 28, 2020 14:07
@adamziel
Copy link
Contributor Author

What's still missing here is distinguishing between the contextual/experimental block navigator and the global one - we don't want to make the text editable in the global navigator.

@@ -193,6 +215,11 @@ function NavigationLinkEdit( {
/>
</PanelBody>
</InspectorControls>
<BlockNavigationListItemFill blockId={ clientId }>
Copy link
Contributor

@talldan talldan Apr 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may be able to avoid the need to pass the clientId here by using something like BlockListBlockContext internally in the BlockNavigationListItemFill, this seems to have the clientId:

const {
clientId,
rootClientId,
isSelected,
isFirstMultiSelected,
isLastMultiSelected,
isMultiSelecting,
isNavigationMode,
isPartOfMultiSelection,
enableAnimation,
index,
className,
isLocked,
name,
mode,
blockTitle,
wrapperProps,
} = useContext( BlockListBlockContext );

Or there might be another way. I think all the other slots (like the sidebar and toolbar) rely on showing only content for the selected block, whereas this use case is a bit different.

@talldan
Copy link
Contributor

talldan commented Apr 29, 2020

What's still missing here is distinguishing between the contextual/experimental block navigator and the global one - we don't want to make the text editable in the global navigator.

We also have the same issue with some of the block toolbar items that we'd ideally not display on the block toolbar in the nav menus page - #21310

One idea might be to use an editor setting (e.g. __experimentalDisableNavigationBlockNavigatorEditing or similar) and adding conditional rendering in the block edit function.

Another option might be applying some filters to the block when registering. That approach would work well for changing the block supports settings to remove alignment options.

@adamziel adamziel force-pushed the add/navigation-menu-block/allow-editing-of-new-menu-items-from-the-block-inspector branch from 768d9cd to 9352479 Compare April 29, 2020 10:41
@adamziel adamziel marked this pull request as ready for review April 29, 2020 11:29
@adamziel
Copy link
Contributor Author

adamziel commented Apr 29, 2020

@talldan Super helpful notes - it thank you so much! Please keep them coming :-)

We also have the same issue with some of the block toolbar items that we'd ideally not display on the block toolbar in the nav menus page - #21310

I believe the problem here is different. While #21310 is definitely relevant, here we want to make sure that the "global" navigator in post editor keeps working the same way, while pretty much every other navigator is editable:

80591719-72544a00-8a1e-11ea-8c9b-152867159ab0

I used contexts for now as they seem the cleanest way out.

@adamziel adamziel self-assigned this Apr 29, 2020
@adamziel
Copy link
Contributor Author

adamziel commented Apr 29, 2020

It's working, although typing in the inspector is super slow - my next step is profiling. Any suggestions and feedback are welcome!

@adamziel
Copy link
Contributor Author

adamziel commented Apr 29, 2020

The root cause of slowness is that every time a block attribute change (e.g. label after every key stroke), we re-render block styles preview in the inspector. This is really slow! I'll look into some optimizations around these styles. Alternatively we could disable rich text editing in the inspector for now.

@adamziel
Copy link
Contributor Author

Performance fix available in #21973 - in the meantime let's get this one reviewed :-)

@adamziel
Copy link
Contributor Author

The performance fix is now merged.

@adamziel adamziel force-pushed the add/navigation-menu-block/allow-editing-of-new-menu-items-from-the-block-inspector branch from 794f184 to 32543c0 Compare May 5, 2020 08:42
@adamziel
Copy link
Contributor Author

adamziel commented May 5, 2020

@talldan I addressed all your feedback. Note that this feature is explicitly enabled in two inspectors in the post editor.

Use Slot/Fill instead of hardcoded components

Disable slots/fills in global editor block navigator

Grab clientId from context instead of requiring a prop

Improve readability of block-navigation/list.js

Use context to determine whether or not given BlockNavigation may be customized with slots

Restore default value for selectBlock in navigation-structure-panel.js

Remove obsolete onChange passed to NavigationStructurePanel

Use constant value for BlockNavigationContext

Use memo() in BlockStyles

Remove performance changes from BlockStyles

Generalize BlockNavigationListItem and remove the BlockNavigationListItemFill for now

Rename useBlockNavigationSlots to withBlockNavigationSlots

Restore RichText in the navigator

Sort out BlockNavigationListItem and BlockNavigationListItemWrapper

Rename BlockNavigationListItemWrapper to BlockNavigationBranch
@adamziel adamziel force-pushed the add/navigation-menu-block/allow-editing-of-new-menu-items-from-the-block-inspector branch from 309c4db to edb8c67 Compare May 6, 2020 13:57
Copy link
Contributor

@talldan talldan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy with this, though I noticed a few minor things I could've caught in an earlier review, so sorry about that @adamziel!

In terms of the user experience, I still have a question over how a user will go about selecting a block that's editable in the navigation. Potentially they could click the icon.

The main concern for me would be having blocks that are editable next to blocks that are not editable and how we present to the user that clicking one does something different to clicking the other.

Having said that, this is only active in an experimental block, so lets move forwards.

We may also want to do some accessibility testing on this, or maybe audit the whole thing at some point if we can get some of the other PRs merged too.

@@ -53,7 +53,7 @@ function BlockNavigationDropdownToggle( { isEnabled, onToggle, isOpen } ) {
);
}

function BlockNavigationDropdown( { isDisabled } ) {
function BlockNavigationDropdown( { isDisabled, withBlockNavigationSlots } ) {
Copy link
Contributor

@talldan talldan May 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be good to make this __experimentalWithBlockNavigationSlots, as it's a publicly exported prop, and it's hard to say what the future is, this may default to true at some point at which point we'd want to remove it gracefully without having to support backwards compatibility.

const blockType = getBlockType( block.name );

return (
<div className="block-editor-block-navigation__item">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed some of the class names don't seem to be right after moving the code around. The root element should have the class name block-editor-block-navigation-list-item to reflect the component name.

export { default as __experimentalBlockNavigationList } from './block-navigation/list';
export {
default as __experimentalBlockNavigationList,
BlockNavigationContext as __experimentalBlockNavigationContext,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this no longer needs to be exported now that it's only used internally in the BlockNavigation components

@adamziel
Copy link
Contributor Author

adamziel commented May 7, 2020

@talldan

Happy with this, though I noticed a few minor things I could've caught in an earlier review, so sorry about that @adamziel!

No worries at all! I just addressed all of them

Having said that, this is only active in an experimental block, so lets move forwards.

Agreed, we'll get there. One option would be to just have it enabled on the experimental nav-menus screen. And even if we decide not to use RichText in the navigator in the end, these slots are going to be useful for the ellipsis menu.

We may also want to do some accessibility testing on this, or maybe audit the whole thing at some point if we can get some of the other PRs merged too.

👍

@talldan
Copy link
Contributor

talldan commented May 8, 2020

Looks like there are some failing e2e tests that are relevant.

@adamziel adamziel requested review from nerrad and ntwb as code owners May 8, 2020 13:40
@adamziel adamziel changed the title Allow editing of new menu items from the block inspector UI Make parts of the BlockNavigationList overridable using slots May 8, 2020
@adamziel
Copy link
Contributor Author

adamziel commented May 8, 2020

@talldan the failures were about the updated class name. I extracted the actual fill out of this PR into #22210 - so this only adds the Slot/Fill machinery. Let's deal with any other test failures in 22210 and unblock the ellipsis menu.

@adamziel adamziel merged commit 655db77 into master May 8, 2020
@github-actions github-actions bot added this to the Gutenberg 8.1 milestone May 8, 2020
@talldan talldan mentioned this pull request May 11, 2020
5 tasks
@aristath aristath deleted the add/navigation-menu-block/allow-editing-of-new-menu-items-from-the-block-inspector branch November 10, 2020 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Affects the Navigation Block [Feature] List View Menu item in the top toolbar to select blocks from a list of links.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants